# coding=utf-8
"""
author = jamon
"""
import hashlib

from obespoir.base.ob_handler import BaseHandler, RegisterEvent
from obespoir.share.espoir_log import global_log as logger

from package.msg_const import MsgID, ResponseStatus


# @RegisterEvent(MsgID.LOGIN)
# class LoginHandler(BaseHandler):
#
#     async def execute(self, *args, **kwargs):
#         logger.info("[login_handler][args=%s][kwargs=%s]", args, kwargs)
#         user_name = self.params.get("name", "")
#         passwd = self.params.get("passwd", "")
#         if not user_name or not passwd:
#             return {}
#         # ...
#         user_id = hash(user_name)
#         return {"code": ResponseStatus.SUCCESS,
#                 "data": {"user_id": user_id, "session_id": self.session_id,
#                          "desc": "恭喜，登录接口测试通过~"}}


@RegisterEvent(MsgID.OFFLINE, need_return=False)
class OfflineHandler(BaseHandler):

    async def execute(self, *args, **kwargs):
        logger.info("[offline][args=%s][kwargs=%s]", args, kwargs)
        pass
        return {"code": ResponseStatus.SUCCESS,
                "data": {"session_id": self.session_id}}


@RegisterEvent(MsgID.HEARTBEAT)
class HeartBeatHandler(BaseHandler):

    async def execute(self, *args, **kwargs):
        logger.info("[heartbeat][args=%s][kwargs=%s]", args, kwargs)
        pass
        return {"code": ResponseStatus.SUCCESS, "data": {
            "session_id": self.session_id}}
